package com.basic.emg.mapper;

import com.basic.emg.domain.*;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.SelectKey;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * 应急队伍
 * @Author: Chn
 * @Create: 2024/10/22
 * @Version: 1.0
 */
public interface EmergencyTeamMapper extends Mapper<EmergencyTeam> {
    @Insert("<script> INSERT INTO team_member_connect (team_id,member_id) VALUES " +
            "    <foreach collection='teamMembers' item='item' index='index' separator=','>\n" +
            "        (#{item.teamId}, #{item.memberId})\n" +
            "    </foreach>" +
            "</script>")
    public int insertTeamMembers(@Param("teamMembers") List<TeamMemberConnect> teamMembers);

    @Insert("insert into emergency_team (team_ref,team_name,member_counts,charge_person,charge_person_tel,belong_dept,create_time,update_time,team_status,del_flag,remarks,addr)\n" +
            "values ( #{teamRef},#{teamName},#{memberCounts},#{chargePerson},#{chargePersonTel},#{belongDept},localtimestamp,localtimestamp,'0','0',#{remarks},#{addr})")
    @SelectKey(statement = "SELECT currval('seq_emergency_pub_id')", keyProperty = "id", before = false, resultType = long.class)
    public int insertTeam( EmergencyTeam team);

    @Insert("insert into team_member (name,post,position,phone,team_id,create_time,del_flag)\n" +
            "values ( #{name},#{post},#{position},#{phone},#{teamId},localtimestamp,'0')")
    @SelectKey(statement = "SELECT currval('seq_emergency_pub_id')", keyProperty = "id", before = false, resultType = long.class)
    public int insertMember( TeamMember teamMember);


}
